#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
#include<windows.h>
#include "蛇和食物初始化.h"
#include "菜单和改变字体颜色函数.h"
#include "游戏主题函数.h"
#include "地图UI初始化.h"

#define WIDE 95//地图宽度
#define HIGH 25//地图高度

void HideCursor() // 用于隐藏光标
{
	CONSOLE_CURSOR_INFO cursor_info = { 1, 0 };  
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}

int main()
{
	HideCursor();
	srand(time(NULL));
	initSnake();
	initFood();
	int input;
	char ch;
	FILE* fp = fopen("最高分.txt", "r");
	fscanf(fp, "%d", &max_score);
	
	while (1)
	{
		welcometogame();
		printf("请选择:");
		scanf("%d", &input);
		while (input != 1 && input != 2 && input != 3 && input != 4)
		{
			printf("请输入正确数字:");
			scanf("%d", &input);
		}

		if (input == 1)
		{
			initUI();
			game();
			set(0, HIGH + 2);
			printf("得分为:%d\n", score);
			printf("目前最高得分为:%d\n", max_score);
			system("pause");
			return 0;
		}
		else if (input == 2)
		{
			system("cls");
			printf("按w a s d键控制蛇移动\n");
			printf("按Q键加速\n");
			printf("按E键减速\n");
			color(2);
			printf("按esc返回...\n");
			color(7);
			while (1)
			{
				ch = _getch();
				if (ch == 27)
				{
					system("cls");
					break;
				}
				else
					continue;
			}
		}
		else if (input == 3)
		{
			fscanf(fp, "%d", &max_score);
			system("cls");
			printf("历史最高分为:%d\n", max_score);
			color(2);
			printf("按esc返回...\n");
			color(7);
			while (1)
			{
				ch = _getch();
				if (ch == 27)
				{
					system("cls");
					break;
				}
				else
					continue;
			}

		}
		else if (input == 4)
		{
			return;
		}
	}
}